package pt.ipl.isel.deetc.leic.pdm.g12.yamba;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class BaseActivity extends Activity {
	protected YambaPdmApp yamba;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		yamba = (YambaPdmApp) getApplication();		
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		
		if( yamba.getPreferences().getString("user", null) == null 
			|| yamba.getPreferences().getString("pass", null) == null){
				startActivity(new Intent(this, PreferencesActivity.class));
				Toast.makeText(this, R.string.setupPreferences, Toast.LENGTH_LONG).show();
		}
	}	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.terminate:
			finish();
			return true;
		case R.id.prefs:
			startActivity( new Intent(this, PreferencesActivity.class)
								.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
			return true;
		case R.id.timeline:
			startActivity( new Intent(this, TimelineActivity.class)
								.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) );
			return true;
		case R.id.status:
			startActivity( new Intent(this, StatusActivity.class)
								.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) );
			return true;
		case R.id.userinfo:
			startActivity( new Intent(this, UserInfoActivity.class)
								.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) );
			return true;
		}
		
		return super.onOptionsItemSelected(item);
	}
}
